//
//  ShopButton.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/7/28.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "ShopButton.h"

@interface ShopButton()

@property (nonatomic,weak) UILabel *tagLab;

@end
@implementation ShopButton

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        UILabel *tagLab = [[UILabel alloc]init];
        tagLab.backgroundColor = [UIColor redColor];
        tagLab.font = Font(10);
        tagLab.textColor = [UIColor whiteColor];
        tagLab.textAlignment = NSTextAlignmentCenter;
        tagLab.layer.cornerRadius = 10;
        tagLab.clipsToBounds = YES;
        tagLab.hidden = YES;
        self.tagLab = tagLab;
        [self addSubview:tagLab];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.imageView.x = (self.width-self.imageView.width)/2.0;
    self.imageView.y = (self.height-self.imageView.height-self.titleLabel.height-5)/2.0;
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.width = self.width;
    self.titleLabel.x = (self.width-self.titleLabel.width)/2.0;
    self.titleLabel.y = CGRectGetMaxY(self.imageView.frame)+5;
    self.tagLab.frame = CGRectMake(CGRectGetMaxX(self.imageView.frame)-self.tagLab.width*0.5+3, self.imageView.y-2, 20, 20 );
}

- (void)setTags:(NSInteger )tags
{
    _tags = tags;
    if (tags == 0) {
        self.tagLab.text = @"0";
        self.tagLab.hidden = YES;
    }else{
        self.tagLab.text = [NSString stringWithFormat:@"%zd",tags];
        self.tagLab.hidden = NO;
    }
}

@end
